package com.easyim.rest.controller;

import com.easyim.rest.service.IUserRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userRelation")
public class UserRelationController {


    @Autowired
    IUserRelationService userRelationService;

    /**
     * 添加关注
     * @return
     */
    @PostMapping("/{user}/follows/{toUser}")
    public ResponseEntity<Boolean> addFollowing(@PathVariable("user") Long user, @PathVariable("toUser") Long following){
        return ResponseEntity.ok(userRelationService.addFollowing(user, following));
    }

    /**
     *  添加朋友
     * @return
     */
    @PostMapping("{user}/friend/{toUser}")
    public ResponseEntity addFriend(@PathVariable("user") Long user, @PathVariable("toUser") Long friend){
        return ResponseEntity.ok(userRelationService.addFriend(user, friend));
    }


    @GetMapping("/{user}/myFollowing")
    public ResponseEntity getMyFollowing(@PathVariable("user") Long user, @RequestParam(value = "page", defaultValue = "0") Integer page,  @RequestParam(value = "size", defaultValue = "10") Integer size){
        //查询我的关注
        return ResponseEntity.ok(userRelationService.getMyFollows(user, page, size));
    }


    @GetMapping("/{user}/getWhoFollowsMe")
    public ResponseEntity getWhoFollowsMe(@PathVariable("user") Long user, @RequestParam(value = "page", defaultValue = "0") Integer page,  @RequestParam(value = "size", defaultValue = "10") Integer size){
        //查询我的关注
        return ResponseEntity.ok(userRelationService.whoFollowMe(user, page, size));
    }


}
